package Y2024.M12.D10;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25228
 * Date: 2024-12-10
 * Time: 11:09
 */
public class Main3 {
    public static void main(String[] args) {
        ExecutorService pool= Executors.newFixedThreadPool(10);
        for (int i = 1; i <= 10; i++) {
            Thread thread=new Thread(new Cup(i));
            pool.execute(thread);
        }
        pool.shutdown();
    }
}
class Cup implements Runnable{
    static double volume=20;
    int number;
    Cup(int number){
        this.number=number;
    }
    @Override
    public void run() {
        Lock lock=new ReentrantLock();
        lock.lock();
        volume=volume-1;
        System.out.println(number+"喝到了水,还剩"+volume);
        lock.unlock();
    }
}